home *** CD-ROM | disk | FTP | other *** search
/ Network Support Library / RoseWare - Network Support Library.iso / apidev / ndr3.exe / VOLSTAT.C < prev    next >
C/C++ Source or Header  |  1993-10-31  |  6KB  |  222 lines

  1. //
  2. // VolStat - Lists all Volume Information for each volume on the
  3. //        current server; distinguishes between Netware OS
  4. //        versions and makes the appropriate (2x or 3x) call
  5. //
  6. // by Charles Rose. Copyright (c) 1993, RoseWare. All Rights Reserved
  7. //
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <dos.h>
  12.  
  13. typedef unsigned char BYTE;
  14. typedef unsigned int WORD;
  15. typedef unsigned long DWORD;
  16.  
  17. /* Reply structure */
  18. struct tag3XInfo {
  19.     DWORD    TotalBlocks;
  20.     DWORD    FreeBlocks;
  21.     DWORD    PurgableBlocks;
  22.     DWORD    NotYetPurgableBlocks;
  23.     DWORD    TotalDirectoryEntries;
  24.     DWORD    AvailableDirectoryEntries;
  25.     DWORD    reserved;
  26.     BYTE    SectorsPerBlock;
  27.     BYTE    VolumeNameLength;
  28.     BYTE    VolumeName[48];
  29. } VolInfo3X;
  30.  
  31. struct tag2XInfo {
  32.     WORD    Length;
  33.     DWORD    ElapsedTime;
  34.     BYTE    VolumeNumber;
  35.     BYTE    LogicalDriveNumber;
  36.     WORD    SectorsPerBlock;
  37.     WORD    StartingBlock;
  38.     WORD    TotalBlocks;
  39.     WORD    AvailableBlocks;
  40.     WORD    TotalDirSlots;
  41.     WORD    AvailableDirSlots;
  42.     WORD    ActualMaxUsedDirSlots;
  43.     BYTE    IsHashed;
  44.     BYTE    IsCached;
  45.     BYTE    IsRemovable;
  46.     BYTE    IsMounted;
  47.     BYTE    VolumeName[16];
  48. } VolInfo2X;
  49.  
  50. int Get3XVolumeInformation( BYTE volume );
  51. void Print3XResults( int x );
  52. int Get2XVolumeInformation( BYTE volume );
  53. void Print2XResults( void );
  54. WORD WordSwap( BYTE *before );
  55. char Is3XSupported( void );
  56. void main();
  57.  
  58. void main()
  59. {
  60.     int x, result;
  61.  
  62.     printf("VOLSTAT Copyright (c) 1993, RoseWare. All Rights Reserved\n\n");
  63.  
  64.     // Check if NetWare 3.x (and above) is supported. If so, make F2h
  65.     // function call, otherwise, use standard 2.x E3h call.  Print
  66.     // results based on type of call made.
  67.  
  68.     if ( Is3XSupported() )
  69.     {
  70.         for ( x = 0; x < 32; x++ )
  71.         {
  72.             result = Get3XVolumeInformation( x );
  73.             if ( !VolInfo3X.TotalBlocks ) exit( 1 );
  74.             else if ( result )
  75.             {
  76.                 printf( "Err: Get3XVolInfo, Vol %d, code %X\n",
  77.                     x, result );
  78.                 exit(1);
  79.             }
  80.             Print3XResults( x );
  81.         }
  82.     }
  83.     else
  84.     {
  85.         for ( x = 0; x < 32; x++ )
  86.         {
  87.             result = Get2XVolumeInformation( x );
  88.             if ( result == 0x98 ) exit( 1 );
  89.             else if ( result )
  90.             {
  91.                 printf( "Err: Get2XVolInfo, Vol %d, code %X\n",
  92.                     x, result );
  93.                 exit(1);
  94.             }
  95.             Print2XResults();
  96.         }
  97.     }
  98. }
  99.  
  100. int Get3XVolumeInformation( BYTE volume )
  101. {
  102.     BYTE Request[4] = { 2, 0, 0x2C, 0 };
  103.  
  104.     Request[3] = volume;
  105.  
  106.     _CX = 4;
  107.     _DX = sizeof( struct tag3XInfo );
  108.     _SI = (unsigned)Request;
  109.     _DI = (unsigned)&VolInfo3X;
  110.  
  111.     // This line needs to preceed any code that manipulates the AX
  112.     // register, since it generates the code:
  113.     //    mov ax, ds
  114.     //    mov ds, ax
  115.     // which clobbers your AX register.  Placing any AX-modifying
  116.     // code after this line, though, is ok.
  117.     _ES = _DS;
  118.     _AX = 0xF216;
  119.  
  120.     geninterrupt( 0x21 );
  121.  
  122.     return _AL;
  123. }
  124.  
  125. int Get2XVolumeInformation( BYTE volume )
  126. {
  127.     BYTE Request[4] = { 2, 0, 0xE9, 0 };
  128.  
  129.     Request[3] = volume;
  130.     VolInfo2X.Length = sizeof( struct tag2XInfo ) - 2;
  131.  
  132.     _SI = (unsigned)Request;
  133.     _DI = (unsigned)&VolInfo2X;
  134.     _ES = _DS;
  135.     _AH = 0xE3;
  136.  
  137.     geninterrupt( 0x21 );
  138.  
  139.     return _AL;
  140. }
  141.  
  142. void Print3XResults( int x )
  143. {
  144.     printf( "Volume #%d [%s]\n", x, VolInfo3X.VolumeName );
  145.  
  146.     printf( "-Storage Space-\n" );
  147.     printf( "   Total Blocks    : %10lu  Total Megabytes : %10lu\n ",
  148.         VolInfo3X.TotalBlocks, ( VolInfo3X.TotalBlocks *
  149.         (DWORD)VolInfo3X.SectorsPerBlock*(DWORD)512)/((DWORD)1024*(DWORD)1024));
  150.     printf( "  Blocks Left     : %10lu  Megabytes Left  : %10lu\n ", VolInfo3X.FreeBlocks,
  151.         ( VolInfo3X.FreeBlocks * (DWORD)VolInfo3X.SectorsPerBlock * (DWORD)512 ) / ( (DWORD)1024 * (DWORD)1024)  );
  152.     printf( "  Purgable Blocks : %10lu  Purgable Megs   : %10lu\n ", VolInfo3X.PurgableBlocks,
  153.         ( VolInfo3X.PurgableBlocks * (DWORD)VolInfo3X.SectorsPerBlock * (DWORD)512 ) / ( (DWORD)1024 * (DWORD)1024)  );
  154.  
  155.     printf( "-Directories-\n" );
  156.     printf( "   Total Entries   : %10lu  Entries Left    : %10lu\n", VolInfo3X.TotalDirectoryEntries,
  157.         VolInfo3X.AvailableDirectoryEntries );
  158.     printf( "\n" );
  159. }
  160.  
  161. void Print2XResults( void )
  162. {
  163.     printf( "Volume #%d [%s]\n", (WORD)VolInfo2X.VolumeNumber, VolInfo2X.VolumeName );
  164.     if ( VolInfo2X.IsHashed ) printf( "Hashed  " ); else printf( "NOT Hashed  " );
  165.     if ( VolInfo2X.IsCached ) printf( "Cached  " ); else printf( "NOT Cached  " );
  166.     if ( VolInfo2X.IsRemovable ) printf( "Removable  " ); else printf( "Fixed  " );
  167.     if ( VolInfo2X.IsMounted ) printf( "Mounted  "   ); else printf( "NOT MOUNTED  " );
  168.     printf( "\n" );
  169.  
  170.     printf( "-Storage Space-\n" );
  171.     printf( "   Total Blocks    : %10d  Total Megabytes : %10lu\n ", WordSwap( (BYTE *)&VolInfo2X.TotalBlocks ),
  172.         ( (DWORD)WordSwap( (BYTE *)&VolInfo2X.TotalBlocks ) *
  173.         (DWORD)WordSwap( (BYTE *)&VolInfo2X.SectorsPerBlock ) *
  174.         (DWORD)512 ) / ((DWORD)1024*(DWORD)1024) );
  175.     printf( "  Blocks Left     : %10d  Megabytes Left  : %10lu\n ", WordSwap( (BYTE *)&VolInfo2X.AvailableBlocks ),
  176.         ( (DWORD)WordSwap( (BYTE *)&VolInfo2X.AvailableBlocks ) *
  177.         (DWORD)WordSwap( (BYTE *)&VolInfo2X.SectorsPerBlock ) *
  178.         (DWORD)512 ) / ((DWORD)1024*(DWORD)1024) );
  179.  
  180.     printf( "-Directories-\n" );
  181.     printf( "   Total Slots     : %10d  Slots Left      : %10d\n", WordSwap( (BYTE *)&VolInfo2X.TotalDirSlots ),
  182.         WordSwap( (BYTE *)&VolInfo2X.AvailableDirSlots ) );
  183.     printf( "\n" );
  184. }
  185.  
  186. char Is3XSupported( void )
  187. {
  188.     char reply[130], retVal;
  189.     BYTE request[3] = { 1, 0, 0x11 };
  190.  
  191.     *((WORD *)reply) = 128;
  192.  
  193.     _SI = (unsigned)request;
  194.     _DI = (unsigned)reply;
  195.     _ES = _DS;
  196.     _AH = 0xE3;
  197.  
  198.     geninterrupt( 0x21 );
  199.  
  200.     retVal = _AL;
  201.  
  202.     if ( retVal )
  203.     {
  204.         printf("Error calling Get File Server Information, ret code = %X\n",
  205.             retVal );
  206.         exit( 1 );
  207.     }
  208.  
  209.     if ( reply[50] >= 3 )
  210.         return 1;
  211.     else
  212.         return 0;
  213. }
  214.  
  215. WORD WordSwap( BYTE *before )
  216. {
  217.     BYTE after[2];
  218.     after[0] = before[1];
  219.     after[1] = before[0];
  220.  
  221.     return *( (WORD *) after );
  222. }